import type { Patient } from './../types/user.d'
import type { CodeType, User, Userinfo } from '@/types/user'
import { request } from '@/utils/request'

export const loginByPassword = (mobile: string, password: string) => {
  return request<User>('/login/password', 'post', { mobile, password })
}

export const sendMobileCode = (mobile: string, type: CodeType) => {
  return request('code', 'GET', { mobile, type })
}

// 短信登录接口API
export const loginByMobile = (mobile: string, code: string) => {
  return request<User>('login', 'post', { mobile, code })
}

// 获取个人信息接口
export const getUserInfo = () => request<Userinfo>('patient/myUser')

// 获取患者信息接口
export const reqGetPaientList = () => request<Patient[]>('/patient/mylist')

// 添加患者接口
export const reqGetAddPatient = (data: Patient) => {
  return request<Patient>('/patient/add', 'post', data)
}

// 修改患者功能
export const reqGetUpdataPatient = (data: Patient) => {
  return request('patient/update', 'put', data)
}

// 删除患者信息
export const reqDelPatient = (id: string) => {
  return request(`/patient/del/${id}`, 'DELETE')
}

/**
 * 极速问诊之支付页面-用户信息渲染
 * @param id {id: patientId}
 */
export const reqGetpatientDetetail = (id: string) => request<Patient>(`/patient/info/${id}`)

// QQ登录
export const loginByQQ = (openId: string) =>
  request<User>('/login/thirdparty', 'POST', { openId, source: 'qq' })

// 绑定手机
export const bindMobile = (data: { mobile: string; code: string; openId: string }) =>
  request<User>('/login/binding', 'POST', data)
